<?php

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 * Description of quanly_hoidap_traloi
 *
 * @author Bui
 */
class Quanly_hoidap_traloi extends CI_Controller {

    //put your code here
    public function __construct() {
        parent::__construct();
        $this->load->helper("url");
        $this->load->model('hoidap_traloi_model');
        $this->load->library("pagination");
    }

    function manage_all_comments() {
        $query = $this->hoidap_traloi_model->load_all_comments();
        // Pagination
        $config = array();
        $config["base_url"] = base_url() . "index.php/hoidap/quanly_hoidap_traloi/manage_all_comment";
        $config["total_rows"] = $this->hoidap_traloi_model->record_count($query);
        $config["per_page"] = 20;
        $config["uri_segment"] = 3;

        $this->pagination->initialize($config);

        $page = ($this->uri->segment(3)) ? $this->uri->segment(3) : 0;
        $data["results"] = $this->hoidap_traloi_model->fetch_data($config["per_page"], $page, $query);
        $data["links"] = $this->pagination->create_links();



        // generate table data
        $this->load->library('table');
        $this->table->set_empty("&nbsp;");
        $this->table->set_heading('username', 'Câu trả lời', 'Xem', 'Xóa');
        foreach ($data['results'] as $row) {
            $this->table->add_row('<b>' . $row->username . '</b>', '<font color="blue"><b>' . 'Rely: ' . $row->tieude . '</b></font>' . '<br>' . $row->noidung, anchor('hoidap/quanly_hoidap_traloi/manage_detail_comment/' . $row->id, 'view', array('class' => 'view')), anchor('/hoidap/quanly_hoidap_traloi/delete_comment/' . $row->id, 'delete', array('class' => 'delete', 'onclick' => "return confirm('Are you sure want to delete this question?')"))
            );
        }

        $data['table'] = $this->table->generate();
        // Load view 'manage_list_comment'
        $this->load->view('user/hoidap/manage_list_comment', $data);
    }

    function manage_detail_comment($id) {
        // Header
        $this->load->view('user/common/header_view', $data);
        $this->load->view('user/common/left_sidebar_view', $data);
        $this->load->view('user/common/head_content_view', $data);
        // Detail comment
        $data['results'] = $this->hoidap_traloi_model->load_comment($id)->row_array();
        $this->load->view('user/hoidap/manage_detail_comment', $data);
        // Footer
        $this->load->view('user/common/right_sidebar_view', $data);
        $this->load->view('user/common/footer_view', $data);
    }

    function delete_comment($id) {
        // Delete comment in table "gs7s_hoidap_traloi"
        $this->hoidap_traloi_model->delete_comment($id);
        // Refresh to update the change
        redirect('hoidap/quanly_hoidap_traloi/manage_all_comments', 'refresh');
    }

}

?>
